<template>
  <div class="row">
      <div v-for="column in columnDataList" :key="column.id" class="col-4 mb-4">
          <!-- <img :src="column.avatar" :alt="column.title">
          <h5>{{ column.title }}</h5>
          <p>{{ column.description }}</p>
          <a href="#">进入专栏</a> -->

          <div class="card h-100 shadow-sm">
            <div class="card-body text-center">
              <img :src="column.avatar.url"  class="card-img-top rounded-circle border border-light  my-3" :alt="column.title">
              <h5 class="card-title">{{ column.title }}</h5>
              <p class="card-text text-left">{{ column.description }}</p>
              <!-- <a href="#" class="btn btn-primary">进入专栏</a> -->
              <router-link class="btn btn-primary" :to='`/column/${column._id}`'>进入专栏</router-link>
            </div>
        </div>
      </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { ColumnProps } from '@/store/index.ts'

// props中构造函数断言类型：PropType
export default defineComponent({
  props: {
    list: {
      //  type: Array,
      type: Array as PropType< ColumnProps[] >,
      required: true,
      default: () => []
    }
  },
  setup(props) {
    const columnDataList = computed(() => {
      return props.list.map(item => {
        if(!item.avatar) {
          // item.avatar = require("@/assets/column.jpg")
          item.avatar = {
            url: require("@/assets/column.jpg")
          }
        }
        return item;
      })
    })
    return {
      columnDataList
    }
  }
})
</script>
<style  scoped>
 .card-body  img {
    width: 50px;
    height: 50px;
  }
</style>
